<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2021/2/25
 * Time: 16:51
 */

namespace app\admin\controller;


use think\Db;

class Beautytipsfeedback extends Base
{
    /**
     * 美丽技巧反馈
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax ()){
            $user_name = input('user_name');
            $user_phone = input('user_phone');
            $where = [];
            if(isset($user_name) && $user_name != ''){
                $where['user_username'] = ['like', "%{$user_name}%"];
            }
            if(isset($user_phone) && $user_phone != ''){
                $where['user_phone'] = ['like', "%{$user_phone}%"];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 100;
            $count = Db::name('beauty_tips_feedback')
                ->join('up_beauty_tips_feedback_type', 'btft_id = btf_type_id', 'LEFT')
                ->join('up_beauty_tips', 'bt_id = btf_bt_id', 'LEFT')
                ->join('up_u_user', 'btf_user_id = user_id', 'LEFT')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('beauty_tips_feedback')
                ->join('up_beauty_tips_feedback_type', 'btft_id = btf_type_id', 'LEFT')
                ->join('up_beauty_tips', 'bt_id = btf_bt_id', 'LEFT')
                ->join('up_u_user', 'btf_user_id = user_id', 'LEFT')
                ->where($where)
                ->field('btf_id, user_username, user_phone, btft_name, btf_is_done, bt_name, btf_time')
                ->order('btf_time desc')
                ->page($Nowpage,$limits)
                ->select();
            
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
    
    /**
     * 处理反馈
     * @return \think\response\Json
     */
    public function beautytipsDone(){
        $btf_id = input('id');
        $res = Db::table('up_beauty_tips_feedback')->where('btf_id', $btf_id)->setField('btf_is_done', 2);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    
    /**
     * 删除反馈
     * @return \think\response\Json
     */
    public function feedbackDel(){
        $btf_id = input('id');
        $res = Db::table('up_beauty_tips_feedback')->delete($btf_id);
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
}